home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks97 / WarriorsProgress.sit / Warrior’s Progress / source code / Source / Libraries / Heap / HeapLink.cp < prev    next >
Text File  |  1997-06-28  |  966b  |  58 lines

  1. // HeapLink.cp
  2.  
  3. #ifndef HeapLink_h
  4. #include "HeapLink.h"
  5. #endif
  6. #ifndef Heap_h
  7. #include "Heap.h"
  8. #endif
  9. #ifndef Swap_h
  10. #include "Swap.h"
  11. #endif
  12. #ifndef Heap_h
  13. #include "Heap.h"
  14. #endif
  15.  
  16. template < class Element >
  17. HeapLink<Element>::HeapLink( Element *e )
  18.   : heap( 0 ),
  19.      body( e ),
  20.      path( 0 )
  21.   {
  22.     children[0] = 0;
  23.     children[1] = 0;
  24.   }
  25.  
  26. template < class Element >
  27. HeapLink<Element>::~HeapLink()
  28.   {
  29.     if ( heap != 0 )
  30.         heap->Remove( *this );
  31.     Assert( heap == 0 );
  32.   }
  33.  
  34. template < class Element >
  35. void HeapLink<Element>::SwapWith( LinkType& r )
  36.   {
  37.     Assert( heap == r.heap );
  38.  
  39.     Swap( path, r.path );
  40.     Swap( children[0], r.children[0] );
  41.     Swap( children[1], r.children[1] );
  42.   }
  43.  
  44. template < class Element >
  45. bool HeapLink<Element>::operator<=( const LinkType& r ) const
  46.   {
  47.     Assert( heap == r.heap );
  48.     Assert( heap != 0 );
  49.     
  50.     Comparator below( heap->Below() );
  51.     Assert( below != 0 );
  52.     
  53.     Assert( !Null() );
  54.     Assert( !r.Null() );
  55.     
  56.     return (body->*below)(*r.body);
  57.   }
  58.